package initialize

import (
	"fmt"
	"github.com/go-redis/redis"
	"go-learn/global"
)

func Redis() *redis.Client {
	redisCfg := global.Config.Redis
	redisOpt := redis.Options{
		Addr:     redisCfg.Addr,
		Password: redisCfg.Password,
		DB:       redisCfg.DB,
	}
	// 创建客户端
	redisClient := redis.NewClient(&redisOpt)
	// 判断是否能够链接到数据库
	_, err := redisClient.Ping().Result()
	if err != nil {
		panic(err)
	}
	fmt.Println("connect redis success")
	return redisClient
}
